<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- data-index data开头规范 -->
    <div getTime='20' data-index="1"></div>

    <script>
        var div = document.querySelector('div');
        console.log(div.getAttribute('getTime'));
        console.log(div.getAttribute('data-index'));
        console.log(div.setAttribute('data-time', '20'));
        //H5新增的获取自定义属性的方法
        console.log(div.dataset);  //dataset 是一个集合里面存放了所有以data开头的自定义属性
        console.log(div.dataset.index);
        console.log(div.dataset['index']);
    </script>
</body>

</html>